<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>订单服务管理页面</title>
    <link rel="stylesheet" href="../res/layui/css/layui.css" media="all">
    <script src="../res/js/jquery-3.1.1.min.js" type="text/javascript"
            charset="utf-8"></script>
    <script type="text/javascript" src="../res/js/login_common.js"></script>
    <script src="../res/layui/layui.js" charset="utf-8"></script>
    <script>
        $.ajaxSetup({
            async: false
        });
    </script>
</head>
<body style="padding: 5px;">
<div class="demoTable">
    <input type="hidden" id="one"/>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script>
    var table2 = null;
    layui.use('table', function () {
        var table = layui.table;
        var form = layui.form;
        dateRender();
        table2 = table.render({
            elem: '#test'
            , url: '../dkm.dkmproject/businessTb/selectAll'
           /* , toolbar: '#headBtn'//开启头部工具栏，并为其绑定左侧模板*/
            , title: '订单服务类型表'
          /*  , done: function (res, curr, count) {
                $("table").css("width", "100%");
            }*/,
            cellMinWidth: 80//全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , cols: [[
                 {field: 'orContent', title: '用户问题描述', width: 160}
                , {field: 'exp1', title: '申请时间', width: 160,templet: "<div>{{layui.util.toDateString(d.exp1, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
                , {field: 'orPhone', title: '用户联系电话', width: 120}
                , {field: 'exp3', title: '用户服务地址', width: 220}
                , {title:'服务状态', width:120,toolbar:'#barDemo4'}
                , {title: '用户图片描述', width: 160,toolbar:'#productimg'}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 180}
            ]]
            , page: true//开启分页
        });

//监听头部工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id), data = checkStatus.data; //获取选中的数据
            switch (obj.event) {
                case 'delAll':
                    layer.confirm('您真的要删除吗', function(index) {
                        var data = checkStatus.data;
                        var id = "";
                        $.each(data, function(index, item) {
                            id += item.pid + ",";
                        });

                        if(id.length==0){
                            layer.msg("请选择需要操作的行");
                            return;
                        }
                        var url ="../../atsPlanYearMoreController/delAll";
                        var datas = {
                            id : id
                        };
                        $.post(url, datas, function(obj) {
                            window.location.reload();
                            layer.msg(obj.msg);
                            dateRender();
                        }, "json");
                    });
                    break;
                case 'seachTable'://搜索
                    $("#one").val($("#nTitle").val());
                    table2.reload({
                        url: '../../news/selectAll',
                        where: {
                            nTitle: $("#nTitle").val()
                        },
                        //第一页开始
                        page: {
                            curr: 1
                        }
                    });
                    $("#nTitle").val($("#one").val());
                    break;
                case 'add'://新增
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '新闻的增加页面',
                        shadeClose: false,//点击父页面关闭层 false给它停止
                        shade: 0.8,
                        area: ['60%', '100%'],
                        content: 'newsAddorUpdate.html', //iframe的url
                        end: function () {
                            dateRender()
                        }
                    });
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if (layEvent === 'del') { //删除
                layer.confirm('真的删除行么', function (index) {
                    var url = "../../news/updateIsva";
                    var datas = {nId:obj.data.nId}
                    $.post(url, datas, function (obj) {
                        if (obj.num == 1) {
                            layer.msg(obj.msg,{icon:1});
                            table2.reload();
                            dateRender()
                        } else {
                            layer.msg(obj.msg);
                        }
                    }, "json")
                });

            }
            if (layEvent === 'look') {
                //iframe层
                layer.open({
                    type: 2,
                    title: '查看新闻详情',//标题
                    shadeClose: true,
                    shade: 0.3,//背景阴影
                    area:['60%', '90%'],//大小
                    content: 'newsLook.html?nId=' + data.nId, //iframew的url
                    end: function () {


                    }
                });
            }
            if(obj.event === 'edit'){
                var data1 = obj.data;//获取当前行
                var url="../dkm.dkmproject/businessTb/updateIsva";
                var data={buId:data1.buId};
                $.post(url,data,function(obj){
                    if(obj.num==1){
                        layer.msg(obj.msg,{icon:1});
                        table2.reload();
                    }else{
                        layer.msg(obj.msg);
                    }
                },"json")
            }
        });

        function dateRender() {
            layui.use(['laydate'], function () {
                laydate = layui.laydate;
                //日期
                laydate.render({
                    elem: '#startTime',
                    trigger: 'click',
                    type: 'date'
                });

                laydate.render({
                    elem: '#endTime',
                    trigger: 'click',
                    type: 'date'
                });
            });
        }
    });
</script>
</body>
<style>
    .details {
        color:#00aced;
        cursor: pointer;
        width: 100%;
        height: 100%;
    }
    .layui-inline {
        width: 12%;
    }
</style>
<script type="text/html" id="headBtn">
    新闻标题名称:
    <div class="layui-inline">
        <input class="layui-input" name="nTitle" id="nTitle" placeholder="请输入关键字" autocomplete="off">
    </div>
    <input type="button" lay-event="seachTable" class="layui-btn layui-btn-normal layui-btn-sm" value="搜索"/>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="add" id="add">增加</button>
</script>
<script type="text/html" id="barDemo">
    {{#if( d.exp2 ==1 ){ }}
    <a class="layui-btn layui-bg-blue  layui-btn-xs layui-icon layui-icon-dialogue" lay-event="edit">立即处理订单</a>
    {{# }else{ }}
    <button class="layui-btn layui-btn-disabled  layui-btn-xs  layui-icon layui-icon-dialogue" lay-event="consulte" disabled="disabled">订单已处理</button>
    {{# } }}
</script>
<script type="text/html" id="productimg">
    <img src='{{getRootPathTwo()+d.orImg}}' alt='图片显示'/>
</script>
<script type="text/html" id="barDemo4">
    {{#if( d.exp2 ==1 ){ }}
    <h3>订单等候处理</h3>
    {{# } }}
    {{#if( d.exp2 ==2 ){ }}
    <h3>订单已派人</h3>
    {{# } }}
</script>
</html>